﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Collections.Generic.IEnumerable<CRM.Models.EquipmentTypesVendorTypes>>" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="CRM.Models" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="DevExpress.XtraGrid" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdEquipmentTypesVendorTypes";
                                        settings.KeyFieldName = "IdEquipmentTypesVendorsTypes";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Dictionaries", Action = "EquipmentTypesVendorTypesPartial" };
                                        settings.SettingsPager.PageSize = 20;

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.EquipmentType;
                                            column.FieldName = "IdEquipmentType";
                                            column.Settings.SortMode = ColumnSortMode.DisplayText;
                                            
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                
                                                comboBoxProperties.DataSource = DB.GetLocalizedEquipmentTypes(
                                                        Thread.CurrentThread.CurrentCulture.ToString());
                                                comboBoxProperties.TextField = "LocaLizedString";
                                                comboBoxProperties.ValueField = "Id";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.VendorType;
                                            column.FieldName = "IdVendorType";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {

                                                comboBoxProperties.DataSource = DB.GetLocalizedVendorsTypesNames(
                                                        Thread.CurrentThread.CurrentCulture.ToString());
                                                comboBoxProperties.TextField = "LocaLizedString";
                                                comboBoxProperties.ValueField = "Id";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.IsActive;
                                            column.FieldName = "IsActive";
                                            column.ColumnType = MVCxGridViewColumnType.CheckBox;
                                        });
                                        
                                        //
                                        //Добавление редактирования
                                        //
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Dictionaries", Action = "EquipmentTypesVendorTypesUpdate" };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Dictionaries", Action = "EquipmentTypesVendorTypesAdd" };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Dictionaries", Action = "EquipmentTypesVendorTypesDelete" };

                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = Unit.Percentage(100);
                                    })
       .Bind(Model).GetHtml();
%>
